//
//  MHMoment.m
// MiaoCircle
//
//Created by acgera on 2018/4/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHMoment.h"

@implementation MHMoment
- (NSMutableArray<MHComment *> *)commentsList
{
    if (_commentsList == nil) {
        _commentsList = [[NSMutableArray alloc] init];
    }
    return _commentsList;
}

- (NSMutableArray<MHUser *> *)attitudesList
{
    if (_attitudesList == nil) {
        _attitudesList = [NSMutableArray array];
    }
    return _attitudesList;
}


-(NSString *)text
{
    return forametTagString(_text);
}

-(IMAUser *)user
{
    if (!_user) {
        _user = [IMAUser new];
        
    }
    _user.nickName = self.publishUserName?:@"";
    _user.userId = [NSString stringWithFormat:@"%d",self.publishUserId];
    _user.icon = self.publishUserHeadPic;
    return _user;
}

-(BOOL)isReplay
{
    return self.recentQA.answerContent.length > 0;
}

+ (NSDictionary *)modelCustomPropertyMapper {
    
    return @{
             @"sourceAllowClick" : @"source_allowclick",
             @"sourceUrl"        : @"source_url",
             //             @"attitudesStatus"  : @"attitudes_status",
             //@"attitudesCount"   : @"attitudes_count",
             //@"attitudesList"    : @"attitudes_list",
             //@"commentsCount"    : @"comments_count",
             //@"commentsList"     : @"comments_list",
             
             @"text"             : @"content",
             @"createdAt"        : @[@"publishTime",@"created"],
             @"picInfos"         : @"attmList",
             @"attitudesList"    : @"likeList",
             @"commentsList"     : @"commentList",
             @"attitudesCount"   : @"likeCount",
             @"attitudesStatus"   :@"isHaveLike",
             @"videoInfo"         :@"vedioObj",
             @"source" :@"circleName",
             };
}

- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
    self.createdAt = [self.createdAt dateByAddingHours:-8];
    return YES;
}


//- (BOOL)modelCustomTransformToDictionary:(NSMutableDictionary *)dic {
//
//    dic[@"createdAt"] = [NSString stringWithFormat:@"%@ %@",dic[@"createdAt"],@"+0800"];
//
//    return YES;
//}


-(MHMomentExtendType)type
{
    if (self.videoInfo.videoURL) {
        _type = MHMomentExtendTypeVideo;
    }else 
    {
        _type = 0;
    }
    
    return _type;
    
    
}

-(BOOL)shareTimeLine
{
    return (self.redInfo.type == RedPacketShare && ![AXAppDelegate sharedDelegate].shareWeChat);
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    
    return @{@"picInfos"        : [MHPicture class],
             @"commentsList"    : [MHComment class],
             @"attitudesList"   : [MHUser class]
             };
}
@end
